Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(install/preflight): cos #103

Merged

Conversation

c3y1huang
Copy link
Contributor

@c3y1huang c3y1huang commented Oct 17, 2024

Which issue(s) this PR fixes:

Issue longhorn/longhorn#9664

What this PR does / why we need it:

Special notes for your reviewer:

Additional documentation or context

Summary by CodeRabbit

  • New Features

    • Improved script for identifying the Container Optimized OS during installation in containerized environments.
  • Bug Fixes

    • Enhanced reliability of the installation process by updating the path for OS identification.

longhorn/longhorn-9664

Signed-off-by: Chin-Ya Huang <[email protected]>
@c3y1huang c3y1huang self-assigned this Oct 17, 2024
Copy link

coderabbitai bot commented Oct 17, 2024

Walkthrough

The changes involve modifications to the Installer struct and its methods in pkg/remote/preflight/installer.go. The primary update is to the newConfigMapForContainerOptimizedOS method, which now retrieves the operating system identifier from ${HOST_MOUNT_DIR}/etc/os-release instead of the previous path. This adjustment aims to enhance the script's ability to correctly identify the Container Optimized OS in a containerized environment. The InstallByContainerOptimizedOS method remains unchanged but utilizes the updated entrypoint script.

Changes

File Path Change Summary
pkg/remote/preflight/installer.go Modified newConfigMapForContainerOptimizedOS to read OS identifier from ${HOST_MOUNT_DIR}/etc/os-release. Updated InstallByContainerOptimizedOS to use the new entrypoint script.

Assessment against linked issues

Objective Addressed Explanation
Correctly identify Container Optimized OS (cos) (9664)
Ensure preflight installer runs without errors on COS (9664)

🐇 In the code, a change so bright,
The OS check now shines with light.
Container Optimized, it finds its way,
With new paths guiding, come what may!
Hops of joy for fixes made,
In the code garden, progress laid! 🌱


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
pkg/remote/preflight/installer.go (1)

Line range hint 134-234: Consider refactoring the shell script for improved maintainability and robustness

While the main issue has been resolved, there are a few suggestions to improve the script:

  1. Consider breaking down the large shell script into smaller, more manageable functions or even separate files. This would improve readability and maintainability.

  2. Add error handling for the cat command in the check_operating_system function. For example:

function check_operating_system() {
    if [ ! -f "${HOST_MOUNT_DIR}/etc/os-release" ]; then
        echo "ERROR: ${HOST_MOUNT_DIR}/etc/os-release file not found"
        exit 1
    fi
    os=$(cat "${HOST_MOUNT_DIR}/etc/os-release" | grep '^ID=' | cut -d= -f2)
    if [ "$os" != "cos" ]; then
        echo "ERROR: Operating system ($os) is not Container Optimized OS (cos)"
        exit 1
    fi
}
  1. Consider using /bin/sh instead of /bin/bash for better compatibility across different systems, unless you specifically need Bash features.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 76f65cd and c587708.

📒 Files selected for processing (1)
  • pkg/remote/preflight/installer.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
pkg/remote/preflight/installer.go (2)

147-147: Correct OS detection for Container Optimized OS

This change addresses the issue described in the PR objectives by modifying the path used to detect the operating system. By using ${HOST_MOUNT_DIR}/etc/os-release instead of /etc/os-release, the script now correctly reads the OS information from the host system rather than from within the container.

This fix should resolve the bug where the OS was incorrectly identified as "sles" instead of "cos" (Container Optimized OS).


Line range hint 1-605: Overall impact of the change is positive and well-integrated

The modification to the OS detection logic in the newConfigMapForContainerOptimizedOS function is well-integrated with the rest of the code. The InstallByContainerOptimizedOS and newDaemonSetForContainerOptimizedOS functions correctly utilize the updated ConfigMap, ensuring that the fix for OS detection is properly applied throughout the installation process.

This change should resolve the issue of incorrect OS detection on Container Optimized OS without introducing any apparent side effects or requiring changes to other parts of the codebase.

@c3y1huang
Copy link
Contributor Author

Test result:

> ./bin/longhornctl-linux-amd64 install preflight --image="c3y1huang/research:longhorn-cli-439" --operating-system="cos"
INFO[2024-10-17T09:51:42+08:00] Initializing preflight installer             
INFO[2024-10-17T09:51:42+08:00] Cleaning up preflight installer              
INFO[2024-10-17T09:51:43+08:00] Running preflight installer                  
INFO[2024-10-17T09:51:43+08:00] Installing dependencies on Container Optimized OS (cos) 
INFO[2024-10-17T09:52:14+08:00] Installed dependencies on Container Optimized OS (cos) 
INFO[2024-10-17T09:52:14+08:00] Cleaning up preflight installer              
INFO[2024-10-17T09:52:14+08:00] Completed preflight installer. Use 'longhornctl check preflight' to check the result. 
> k get pod
NAME                                READY   STATUS    RESTARTS   AGE
longhorn-gke-cos-node-agent-q5vvs   1/1     Running   0          44s
longhorn-gke-cos-node-agent-rslvt   1/1     Running   0          44s
longhorn-gke-cos-node-agent-wvjkp   1/1     Running   0          44s

@derekbit derekbit merged commit 3715dba into longhorn:master Oct 17, 2024
8 checks passed
@derekbit
Copy link
Member

@mergify backport v1.7.x

Copy link

mergify bot commented Oct 17, 2024

backport v1.7.x

✅ Backports have been created

@c3y1huang c3y1huang deleted the 9664-fix-install-preflight-for-cos branch October 17, 2024 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants